﻿using Microsoft.AspNetCore.Mvc;
using Step4.Unit9.Filters;
using Step4.Unit9.Models;
using System.Diagnostics;

namespace Step4.Unit9.Controllers
{
    // [CustomerExceptionFilter]  // 这中方式只适合于“自定义过滤器中没有任何依赖注入的”，如果有依赖注入就不能这么用了

    //  类型过滤器  TypeFilterAttribute
    //  [TypeFilter(typeof(CustomerExceptionFilterAttribute))]  // 这种方式“类型过滤器”可以将有依赖注入的过滤器类添加到 控制器和 Action
    public class HomeController : Controller
    {
        private readonly ILogger<HomeController> _logger;
        private readonly IConfiguration _configuration;

        public HomeController(ILogger<HomeController> logger, IConfiguration configuration)
        {
            _logger = logger;
            _configuration = configuration;
        }

        // “服务过滤器” ServiceFilterAttribute
        // 此种方式一般要将过滤器类添加到容器中去
        // [ServiceFilter(typeof(CustomerExceptionFilterAttribute))]
        public IActionResult Index()
        {
            var a = _configuration["test"].ToString();
            return View();
        }

        public IActionResult Privacy()
        {
            return View();
        }

        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }
    }
}
